capture log close
clear

log using Log_UnifiedAnalysis.txt, text replace

set scheme s1mono
graph set window fontface "Times New Roman"

use Study1data_publicdatafile_cleaned.dta
append using Study2data_publicdatafile_cleaned.dta, force
append using StudyR1data_publicdatafile_cleaned.dta, force

/* Code up demographics for Study 1 and Study (Study R1 already done in datafile, with prefix d_) */

* Age for all respondents, in years
gen D_age=x_age
label var D_age "Age in years"

* gender
gen D_female = x_female
label var D_female "Female (1=yes, else=0)"

* 4 category education
gen D_educ=.
replace D_educ=1 if x_education == "Some high school or less" | x_education ==  "High school graduate" | x_education == "Other post high school vocational training"
replace D_educ=2 if x_education == "Associate's degree"  | x_education ==  "Completed some college, but no degree"
replace D_educ=3 if x_education == "Bachelor's degree"
replace D_educ=4 if x_education == "Doctorate degree"  | x_education ==  "Master's or professional degree"
label var D_educ "Education (1=HS or less, 4=Post BA)"

* race/ethnicity
gen temp_ethnicity=real(ethnicity)
replace temp_ethnicity=1 if x_ethnicity=="White",
replace temp_ethnicity=2 if x_ethnicity=="Black, or African American",
replace temp_ethnicity=3 if x_ethnicity=="American Indian or Alaska Native",
replace temp_ethnicity=4 if x_ethnicity=="Asian *** Asian Indian",
replace temp_ethnicity=5 if x_ethnicity=="Asian *** Chinese",
replace temp_ethnicity=6 if x_ethnicity=="Asian *** Filipino",
replace temp_ethnicity=7 if x_ethnicity=="Asian *** Japanese",
replace temp_ethnicity=8 if x_ethnicity=="Asian *** Korean",
replace temp_ethnicity=9 if x_ethnicity=="Asian *** Vietnamese",
replace temp_ethnicity=10 if x_ethnicity=="Asian *** Other",
replace temp_ethnicity=11 if x_ethnicity=="Pacific Islander *** Native Hawaiian",
replace temp_ethnicity=12 if x_ethnicity=="Pacific Islander *** Guamanian",
replace temp_ethnicity=13 if x_ethnicity=="Pacific Islander *** Samoan",
replace temp_ethnicity=14 if x_ethnicity=="Pacific Islander *** Other Pacific Islander",
replace temp_ethnicity=15 if x_ethnicity=="Some other race",
replace temp_ethnicity=16 if x_ethnicity=="Prefer not to answer"

gen D_ethnicity_refused=temp_ethnicity==16
gen D_ethnicity_black=temp_ethnicity==2
gen D_ethnicity_other=(temp_ethnicity>=3 & temp_ethnicity<=15)
label var D_ethnicity_refused "Race refused (1=yes)"
label var D_ethnicity_black "Race = Black/African American (1=yes)"
label var D_ethnicity_other "Race = Other (1=yes)"
drop temp_ethnicity

gen D_hispanic=Whispanic=="Hispanic" if Whispanic~=""
gen temp=real(hispanic)
replace D_hispanic = 1 if temp >=2 & temp <=15
replace D_hispanic = 0 if temp ==1 | temp ==16
drop temp
tab D_hispanic
label var D_hispanic "Hispanic (1=yes)"

label define B_l 0 "Respondent not Black" 1 "Respondent is Black" 
label define H_l 0 "Respondent not Hispanic" 1 "Respondent is Hispanic" 

label values D_ethnicity_black B_l
label values D_hispanic H_l

* Income
gen temphhi=x_hhi_n
replace temphhi=real(hhi) if hhi~=""
gen D_hhinc=.
replace D_hhinc=1 if temphhi>=1 &  temphhi<=3
forvalues ctr=4(1)27 {
	replace D_hhinc=`ctr'-2 if temphhi==`ctr'
	}
label var D_hhinc "Household Income (1=<15K, 24=250K+, 25=RF)"
gen D_hhinc_RF=D_hhinc==25
label var D_hhinc_RF "Income refused"

keep D_* S1out_expectedpunish_vig1 treat_officerwhite S1treat_demeanor S2treat_demeanor treat_weapon S1out_prefpunish_vig2 S1out_fair_pun_vig2 S1out_fair_global_vig2  treat_ticket s2_out_preferpun treat_arrest  s2_out_threat_cop  s2_out_threat_vic  s2_out_expectedpun  s2_out_fairnesspun s2_out_fairnesglob alt2_treat_tic_dmnr alt_treat_arst_dmnr  treat_arst_weapon d_age- T_i_demeanor4 study

**************************************************************************************************
* Additional recodings
**************************************************************************************************

* generate demeanor*ticket indicators for study 1. Outreg crashes when using ## operator
gen S1_X_demeanor2_ticket= (S1treat_demeanor==2)*treat_ticket
gen S1_X_demeanor3_ticket= (S1treat_demeanor==3)*treat_ticket
gen S1_X_demeanor4_ticket= (S1treat_demeanor==4)*treat_ticket
gen S1_X_demeanor5_ticket= (S1treat_demeanor==5)*treat_ticket
label var S1_X_demeanor2_ticket "Hostile Civilian, Polite Officer X Ticketed"
label var S1_X_demeanor3_ticket "Both Hostile (Civilian first) X Ticketed"
label var S1_X_demeanor4_ticket "Both Hostile (Officer first) X Ticketed"
label var S1_X_demeanor5_ticket "Polite Civilian, Hostile Officer X Ticketed"

* generate demeanor*ticket indicators for study R1. Outreg crashes when using ## operator
gen SR1_X_demeanor1_ticket= (T_demeanor==1)*T_officerdecision
gen SR1_X_demeanor2_ticket= (T_demeanor==2)*T_officerdecision
gen SR1_X_demeanor3_ticket= (T_demeanor==3)*T_officerdecision
label var SR1_X_demeanor1_ticket "Hostile Civilian, Polite Officer X Ticketed"
label var SR1_X_demeanor2_ticket "Both Hostile (Officer first) X Ticketed"
label var SR1_X_demeanor3_ticket "Polite Civilian, Hostile Officer X Ticketed"

* generate demeanor*arrest and weapons*arrest indicators for study 2.
gen S2_X_demeanor2_arrest= (S2treat_demeanor==2)*treat_arrest
gen S2_X_demeanor3_arrest= (S2treat_demeanor==3)*treat_arrest
gen S2_X_demeanor4_arrest= (S2treat_demeanor==4)*treat_arrest
label var S2_X_demeanor2_arrest "Hostile Civilian, Polite Officer X Arrested"
label var S2_X_demeanor3_arrest "Both Hostile (Officer first) X Arrested"
label var S2_X_demeanor4_arrest "Polite Civilian, Hostile Officer X Arrested"

gen S2_X_weapon_arrest= treat_weapon*treat_arrest
label var S2_X_weapon_arrest "Weapon X Arrested"

**************************************************************************************************
* Study 1, Figure Appendix Figure 1
* Treatments affect expected punishments
**************************************************************************************************

regress S1out_expectedpunish_vig1 i.treat_officerwhite i.S1treat_demeanor, robust
est store S1out_expectedpunish_vig1 

qui summ S1out_expectedpunish_vig1  if e(sample)
local sampmean=r(mean)

* Predicted outcome for baseline category
local base_S1out_expectedpunish_vig1  = _b[_cons]

* Effect of civilian becoming hostile given officer already hostile
* So does civilian stay calm? How much worse is for the civilian to get angry back?
lincom 4.S1treat_demeanor - 5.S1treat_demeanor
local est45=r(estimate)
local p_est45=r(p)

* Effect of civilian rather than officer starting hostile interaction
lincom 3.S1treat_demeanor - 4.S1treat_demeanor
local est34=r(estimate)
local p_est34=r(p)	

outreg using TableA1_Study1Results.out, se bracket rdec(2) bdec(2) 3aster addstat("Sample mean",`sampmean',"FX Civ. responds to hostility vs remains polite",`est45',"p. diff 1",`p_est45',"FX Civ. rather than officer starting hostile interaction",`est34',"p. diff 2",`p_est34') adec(2) replace

* Create Appendix Figure 1, Panel A
local baseline : display %4.2f `base_S1out_expectedpunish_vig1'

coefplot S1out_expectedpunish_vig1  , drop(_cons) levels(95) omitted baselevels headings(0.treat_officerwhite = `"{bf:Officer Race}"' 1.S1treat_demeanor = "{bf:Demeanor}") xline(0) title("A) Experiment #1", span size(small)) xlabel(, labels labsize(vsmall)) xtitle("Expected Punishment") ylabel(, labels labsize(small)) legend(off) note("Expected punishment ranges from 1 to 5." "Predicted baseline punishment for Black officer/Both polite is `baseline'", span size(vsmall)) xscale(range(-.25(.5)1.75)) xlabel(0(.5)1.5) grid(within )  name(AppendixF1A_S1s2_out_expectedpun, replace) 

* This block tests whether the race x demeanor interactions improve model fit using a likelihood ratio test
* They reveal that the interactions do not, so we can ignore race x demeanor in the first stage. Can't do robust with LR
	qui regress S1out_expectedpunish_vig1 i.treat_officerwhite i.S1treat_demeanor
	estimates store base
		
	* Just demeanor ticket interactions
	qui regress S1out_expectedpunish_vig1 i.treat_officerwhite##i.S1treat_demeanor
	estimates store m_racedem

	di "DV=`var' Test of whether race interactions improve fit"
	lrtest base m_racedem, stats

**************************************************************************************************
* Study 2, Figure Appendix Figure 1
* Treatments affect expected punishments
**************************************************************************************************

regress s2_out_expectedpun i.treat_officerwhite i.S2treat_demeanor i.treat_weapon , robust
est store s2_out_expectedpun

qui summ s2_out_expectedpun if e(sample)
local sampmean=r(mean)

* Predicted outcome for baseline category
local base_s2_out_expectedpun = _b[_cons]

outreg using TableA5_Study2Results.out, se bracket rdec(2) bdec(2) adec(2) 3aster addstat("Sample mean",`sampmean') replace

* Create Appendix Figure A, Panel B
local baseline : display %4.2f `base_s2_out_expectedpun'

coefplot s2_out_expectedpun , drop(_cons) levels(95) omitted baselevels headings(0.treat_officerwhite = `"{bf:Officer Race}"' 1.S2treat_demeanor = "{bf:Demeanor}"0.treat_weapon= "{bf:Weapon}") xline(0) title("B) Experiment #2", span size(small)) xlabel(, labels labsize(vsmall)) xtitle("Expected Punishment") ylabel(, labels labsize(small)) legend(off) note("Expected punishment ranges from 1 to 5." "Predicted baseline punishment for Black officer/Both polite/No weapon is `baseline'", span size(vsmall))  xscale(range(-.25(.5)1.75)) xlabel(0(.5)1.5) grid(within ) name(AppendixF1B_s2_out_expectedpun, replace) 

* Create combined Figure 1, panels A and B
graph combine AppendixF1A_S1s2_out_expectedpun AppendixF1B_s2_out_expectedpun, xcommon cols(1) title(Effect of Vignette Characteristics on Expected Punishment) note("Point estimates displayed with 95% confidence intervals. Prior to punishment being revealed. Regression results appear in Appendix Tables A1 and Table A2.", size(vsmall)) name(AppendixFigure1_Combined, replace) xsize(9) ysize(6.5) scale(.9)
graph export AppendixFigure1.pdf, replace

**************************************************************************************************
* Study 1, Figure 1
* Treatments affect preferred punishments
**************************************************************************************************

regress S1out_prefpunish_vig2 i.S1treat_demeanor i.treat_officerwhite i.treat_ticket, robust
qui summ S1out_prefpunish_vig2 if e(sample)
local sampmean=r(mean)

* Predicted outcome for baseline category
local base_S1out_prefpunish_vig2 = _b[_cons]

* Effect of civilian becoming hostile given officer already hostile
* So does civilian stay calm? How much worse is for the civilian to get angry back?
lincom 4.S1treat_demeanor - 5.S1treat_demeanor
local est45=r(estimate)
local p_est45=r(p)

* Effect of civilian rather than officer starting hostile interaction
lincom 3.S1treat_demeanor - 4.S1treat_demeanor
local est34=r(estimate)
local p_est34=r(p)	

est store S1out_prefpunish_vig2

*What happens if the officer becomes angry after the civilian is hostile? Do people want less punishment? No
lincom 2.S1treat_demeanor - 3.S1treat_demeanor

outreg using TableA1_Study1Results.out, se bracket rdec(2) bdec(2) 3aster addstat("Sample mean",`sampmean',"FX Civ. responds to hostility vs remains polite",`est45',"p. diff 1",`p_est45',"FX Civ. rather than officer starting hostile interaction",`est34',"p. diff 2",`p_est34') adec(2) append

* Create Figure 1, Panel A
local baseline : display %4.2f `base_S1out_prefpunish_vig2'
coefplot S1out_prefpunish_vig2 , drop(_cons) levels(95) omitted baselevels headings(0.treat_officerwhite = `"{bf:Officer Race}"' 1.S1treat_demeanor = "{bf:Demeanor}" 0.treat_ticket = "{bf:Punishment}") xline(0) title("A) Experiment #1", span size(small)) xlabel(, labels labsize(vsmall)) xtitle("Preferred Punishment") ylabel(, labels labsize(small)) legend(off) note("Preferred punishment ranges from 1 to 6." "Predicted preferred punishment for Black officer/Both polite/Escorted from park is `baseline'", span size(vsmall)) xscale(range(-.25(.25)1)) xlabel(-.25(.25)1) grid(within ) name(F1A_S1_preferredpunish_vig2, replace) 

* This block tests whether the race x demeanor interactions improve model fit using a likelihood ratio test
* Nulls, reported in text.
	qui regress S1out_prefpunish_vig2 i.treat_officerwhite i.S1treat_demeanor i.treat_ticket
	estimates store base
	qui regress S1out_prefpunish_vig2 i.treat_officerwhite##ib1.S1treat_demeanor i.treat_ticket
	estimates store m_racedemortic
	di "DV=`var' Test of whether race x demeanor interactions improve fit"
	lrtest base m_racedemortic , stats

* With demographics
regress S1out_prefpunish_vig2 i.treat_officerwhite i.S1treat_demeanor i.treat_ticket D_*, robust
outreg using TableA2_Study1ResultsWithCovariates.out, se bracket rdec(2) bdec(2) 3aster replace

**************************************************************************************************
* Study 1, Ordered Probit Estimates
* Treatments affect preferred punishments
**************************************************************************************************

oprobit S1out_prefpunish_vig2 i.treat_officerwhite i.S1treat_demeanor i.treat_ticket, robust
outreg using TableA9_PooledProbitResults.out, se bracket rdec(2) bdec(2) 3aster replace

* Predicted probability people want a ticket.
margins treat_officerwhite, predict(outcome(5))
marginsplot, recast(bar) xtitle("") ytitle(Predicted Probability) xlabel(,angle(45) labsize(small)) title("Predicted Probability Prefer Ticket Outcome") note(Ordered Probit Estimates and 95% confidence intervals) name(vig2_op_offrace, replace)

margins S1treat_demeanor, predict(outcome(5))
marginsplot, recast(bar) xtitle("") ytitle(Predicted Probability) xlabel(,angle(45) labsize(small)) title("Predicted Probability Prefer Ticket Outcome") note(Ordered Probit Estimates and 95% confidence intervals) name(vig2_op_demeanor, replace)

margins treat_ticket, predict(outcome(5))
marginsplot, recast(bar) xtitle("") ytitle(Predicted Probability) xlabel(,angle(45) labsize(small)) title("Predicted Probability Prefer Ticket Outcome") note(Ordered Probit Estimates and 95% confidence intervals) name(vig2_op_ticket, replace)

graph combine vig2_op_offrace vig2_op_ticket, ycommon name(p1, replace) col(1)
graph combine p1 vig2_op_demeanor, ycommon name(S1_vig2_oprobitmfx, replace) title("Study 1, Ordered Probit Marginal Effects")

**************************************************************************************************
* Study R1, Figure 1
* Treatments affect preferred punishments
**************************************************************************************************

regress SR1_out_preferredpunish i.T_demeanor i.T_officerwhite i.T_civilianwhite  i.T_officerdecision, robust
qui summ SR1_out_preferredpunish if e(sample)
local sampmean=r(mean)

* Predicted outcome for baseline category
local base_SR1_out_preferredpunish = _b[_cons]

* So does civilian stay calm? How much worse is for the civilian to get angry back?
lincom 3.T_demeanor - 2.T_demeanor
local est32=r(estimate)
local p_est32=r(p)

est store SR1_out_preferredpunish

outreg using TableA3_StudyR1Results.out, se bracket rdec(2) bdec(2) 3aster addstat("Sample mean",`sampmean',"FX Civ. responds to hostility vs remains polite",`est32',"p. diff 1",`p_est32') adec(2) replace

local baseline : display %4.2f `base_SR1_out_preferredpunish'

* Create Figure 1, Panel B
coefplot SR1_out_preferredpunish , drop(_cons) levels(95) omitted baselevels headings(0.T_civilianwhite = `"{bf:Civilian Race}"' 0.T_officerwhite = `"{bf:Officer Race}"' 0.T_demeanor = "{bf:Demeanor}" 0.T_officerdecision = "{bf:Punishment}") xline(0) title("B) Experiment R1", span size(small)) xlabel(, labels labsize(vsmall)) xtitle("Preferred Punishment") ylabel(, labels labsize(small)) legend(off) note("Preferred punishment ranges from 1 to 6." "Predicted preferred punishment for White officer/White civilian/Both polite/Escorted from park is `baseline'", span size(vsmall)) xscale(range(-.25(.25)1)) xlabel(-.25(.25)1) grid(within ) name(F1B_SR1_out_preferredpunish, replace)

* With demographics
regress SR1_out_preferredpunish i.T_demeanor i.T_officerwhite i.T_civilianwhite i.T_officerdecision d_*, robust
outreg using TableA4_StudyR1ResultsWithCovariates.out, se bracket rdec(2) bdec(2) 3aster replace

* Robustness of office/civilian race interactions: Effect only manifests when both are white.
regress SR1_out_preferredpunish i.T_demeanor T_x_bothwhite T_x_offwhitecivblack T_x_offwblackcivwhite i.T_officerdecision, robust
outreg using TableA3_StudyR1Results.out, se bracket rdec(2) bdec(2) 3aster append

* Repeating by demeanor
regress SR1_out_preferredpunish  T_x_bothwhite T_x_offwhitecivblack T_x_offwblackcivwhite i.T_officerdecision if T_demeanor==0, robust
outreg using TableA3_StudyR1Results.out, se bracket rdec(2) bdec(2) 3aster ctitle("Both polite") append

regress SR1_out_preferredpunish  T_x_bothwhite T_x_offwhitecivblack T_x_offwblackcivwhite i.T_officerdecision if T_demeanor==1, robust
outreg using TableA3_StudyR1Results.out, se bracket rdec(2) bdec(2) 3aster ctitle("Hostile Civilian, Polite Officer") append

regress SR1_out_preferredpunish  T_x_bothwhite T_x_offwhitecivblack T_x_offwblackcivwhite i.T_officerdecision if T_demeanor==2, robust
outreg using TableA3_StudyR1Results.out, se bracket rdec(2) bdec(2) 3aster ctitle("Both Hostile (Officer First)") append

regress SR1_out_preferredpunish  T_x_bothwhite T_x_offwhitecivblack T_x_offwblackcivwhite i.T_officerdecision if T_demeanor==3, robust
outreg using TableA3_StudyR1Results.out, se bracket rdec(2) bdec(2) 3aster ctitle("Hostile Civilian, Hostile Officer") append

* Among Black respondents
regress SR1_out_preferredpunish i.T_demeanor i.T_officerwhite i.T_civilianwhite  i.T_officerdecision if d_black==1, robust
qui summ SR1_out_preferredpunish if e(sample)
local sampmean=r(mean)
outreg using TableA4_StudyR1ResultsWithCovariates.out, se bracket rdec(2) bdec(2) 3aster ctitle("Preferred Punishment, Black respondents") addstat("Sample mean",`sampmean') adec(2) append

* Among White respondents
regress SR1_out_preferredpunish i.T_demeanor i.T_officerwhite i.T_civilianwhite  i.T_officerdecision if d_black==0 & d_asian==0 & d_other==0, robust
qui summ SR1_out_preferredpunish if e(sample)
local sampmean=r(mean)
outreg using TableA4_StudyR1ResultsWithCovariates.out, se bracket rdec(2) bdec(2) 3aster ctitle("Preferred Punishment, White respondents (Incl. Hispanic)") addstat("Sample mean",`sampmean') adec(2) append

* This block tests whether the officer race x demeanor interactions improve model fit using a likelihood ratio test
* Nulls, reported in text.
	qui regress SR1_out_preferredpunish i.T_demeanor i.T_officerwhite i.T_civilianwhite i.T_officerdecision
	estimates store base
	qui regress SR1_out_preferredpunish i.T_demeanor##i.T_officerwhite i.T_civilianwhite i.T_officerdecision
	estimates store m_racedemortic
	di "DV=`var' Test of whether offcier race x demeanor interactions improve fit"
	lrtest base m_racedemortic , stats

* This block tests whether the civilian race x demeanor interactions improve model fit using a likelihood ratio test
* Nulls, reported in text.
	qui regress SR1_out_preferredpunish i.T_demeanor i.T_officerwhite i.T_civilianwhite i.T_officerdecision
	estimates store base
	qui regress SR1_out_preferredpunish i.T_demeanor##i.T_civilianwhite i.T_officerwhite i.T_officerdecision
	estimates store m_racedemortic
	di "DV=`var' Test of whether offcier race x demeanor interactions improve fit"
	lrtest base m_racedemortic , stats

**************************************************************************************************
* Study R1, Ordered Probit Estimates
* Treatments affect preferred punishments
**************************************************************************************************

oprobit SR1_out_preferredpunish i.T_demeanor i.T_officerwhite i.T_civilianwhite  i.T_officerdecision, robust
outreg using TableA9_PooledProbitResults.out, se bracket rdec(2) bdec(2) 3aster append

* Predicted probability people want a ticket.
margins T_officerwhite, predict(outcome(5))
marginsplot, recast(bar) xtitle("") ytitle(Predicted Probability) xlabel(,angle(45) labsize(small)) title("Predicted Probability Prefer Ticket Outcome") note(Ordered Probit Estimates and 95% confidence intervals) name(vig2_op_offrace, replace)

margins T_civilianwhite, predict(outcome(5))
marginsplot, recast(bar) xtitle("") ytitle(Predicted Probability) xlabel(,angle(45) labsize(small)) title("Predicted Probability Prefer Ticket Outcome") note(Ordered Probit Estimates and 95% confidence intervals) name(vig2_op_civrace, replace)

margins T_demeanor, predict(outcome(5))
marginsplot, recast(bar) xtitle("") ytitle(Predicted Probability) xlabel(,angle(45) labsize(small)) title("Predicted Probability Prefer Ticket Outcome") note(Ordered Probit Estimates and 95% confidence intervals) name(vig2_op_demeanor, replace)

margins T_officerdecision, predict(outcome(5))
marginsplot, recast(bar) xtitle("") ytitle(Predicted Probability) xlabel(,angle(45) labsize(small)) title("Predicted Probability Prefer Ticket Outcome") note(Ordered Probit Estimates and 95% confidence intervals) name(vig2_op_ticket, replace)

graph combine vig2_op_offrace vig2_op_civrace vig2_op_ticket, ycommon name(p1, replace) col(1)
graph combine p1 vig2_op_demeanor, ycommon name(SR1_vig2_oprobitmfx, replace) title("Study R1, Ordered Probit Marginal Effects")

**************************************************************************************************
* Study 2, Figure 1
* Treatments affect preferred punishments
**************************************************************************************************

tab s2_out_preferpun
tab s2_out_preferpun, nolabel

regress s2_out_preferpun i.S2treat_demeanor i.treat_weapon i.treat_officerwhite i.treat_arrest, robust
est store s2_out_preferpun

qui summ s2_out_preferpun if e(sample)
local sampmean=r(mean)

* Predicted outcome for baseline category
local base_s2_out_preferpun = _b[_cons]
	
outreg using TableA5_Study2Results.out, se bracket rdec(2) bdec(2) adec(2) 3aster addstat("Sample mean",`sampmean') append

* Create Figure 3, Panel C
local baseline : display %4.2f `base_s2_out_preferpun'
coefplot s2_out_preferpun , drop(_cons) levels(95) omitted baselevels headings(0.treat_officerwhite = `"{bf:Officer Race}"' 1.S2treat_demeanor = "{bf:Demeanor}"0.treat_weapon= "{bf:Weapon}" 0.treat_arrest = "{bf:Punishment}") xline(0) title("C) Experiment #2", span size(small)) xlabel(, labels labsize(vsmall)) xtitle("Preferred Punishment") ylabel(, labels labsize(small)) legend(off) note("Preferred punishment ranges from 1 to 5." "Predicted baseline preferred punishment for Black officer/Both polite/No weapon/Ticketed is `baseline'", span size(vsmall)) xscale(range(-.25(.25)1)) xlabel(-.25(.25)1) grid(within ) name(F1C_S2_preferredpunish_vig2, replace) 

* Build figure 1
graph combine F1A_S1_preferredpunish_vig2 F1B_SR1_out_preferredpunish F1C_S2_preferredpunish_vig2, xcommon cols(1) title("Effect of Vignette Characteristics on Preferred Punishment", size(medium)) note("Point estimates displayed with 95% confidence intervals. Regression results in Appendix Tables A1-A3.", size(vsmall)) name(Figure1_Combined, replace) xsize(6.5) ysize(9) scale(.8)
graph export Figure1.pdf, replace

* HERE IS THE TEST FOR RACE OF OFFICER INTERACTIONS. NULLS. REPORTED IN TEXT
	qui regress s2_out_preferpun i.treat_officerwhite i.S2treat_demeanor i.treat_weapon i.treat_arrest
	estimates store base

	qui regress s2_out_preferpun i.treat_officerwhite##ib1.S2treat_demeanor i.treat_officerwhite##i.treat_weapon i.treat_arrest
	estimates store m_racedemortic

	di "DV=s2_out_preferpun Test of whether race x demeanor interactions improve fit"
	lrtest base m_racedemortic , stats

* FOR STUDY 2, WE CAN ALSO EXAMINE WEAPON X DEMEANOR INTERACTIONS
	qui regress s2_out_preferpun i.treat_officerwhite i.S2treat_demeanor i.treat_weapon i.treat_arrest
	estimates store base

	* This is the estimate discussed in the text
	* Hostile Citizen, Polite Officer#Baseball bat  |  -.1880086    .146561    -1.28   0.200    -.4754255    .0994084
	regress s2_out_preferpun i.treat_officerwhite i.S2treat_demeanor##i.treat_weapon i.treat_arrest
	estimates store m_demeanorweapon

	di "DV=s2_out_preferpun Test of whether demeanor x weapons interactions improve fit"
	lrtest base m_demeanorweapon , stats

* Model with demographics
regress s2_out_preferpun i.treat_officerwhite i.S2treat_demeanor i.treat_weapon i.treat_arrest D_*, robust
outreg using TableA6_Study2ResultsWithCovariates.out, se bracket rdec(2) bdec(2) 3aster replace

**************************************************************************************************
* Study 2,  Ordered Probit Estimates
* Treatments affect preferred punishments
**************************************************************************************************

oprobit s2_out_preferpun i.treat_officerwhite i.S2treat_demeanor i.treat_weapon i.treat_arrest, robust
outreg using TableA9_PooledProbitResults.out, se bracket rdec(2) bdec(2) 3aster append

* Predicted probability people want a ticket.
margins treat_officerwhite, predict(outcome(5))
marginsplot, recast(bar) xtitle("") ytitle(Predicted Probability) xlabel(,angle(45) labsize(small)) title("Predicted Probability Prefer Arrest") note(Ordered Probit Estimates and 95% confidence intervals) name(vig2s2_op_offrace, replace)

margins S2treat_demeanor, predict(outcome(5))
marginsplot, recast(bar) xtitle("") ytitle(Predicted Probability) xlabel(,angle(45) labsize(small)) title("Predicted Probability Prefer Arrest") note(Ordered Probit Estimates and 95% confidence intervals) name(vig2s2_op_demeanor, replace)

margins treat_weapon, predict(outcome(5))
marginsplot, recast(bar) xtitle("") ytitle(Predicted Probability) xlabel(,angle(45) labsize(small)) title("Predicted Probability Prefer Arrest") note(Ordered Probit Estimates and 95% confidence intervals) name(vig2s2_op_weapon, replace)

margins treat_arrest, predict(outcome(5))
marginsplot, recast(bar) xtitle("") ytitle(Predicted Probability) xlabel(,angle(45) labsize(small)) title("Predicted Probability Prefer Arrest") note(Ordered Probit Estimates and 95% confidence intervals) name(vig2s2_op_ticket, replace)

graph combine vig2s2_op_offrace  vig2s2_op_weapon vig2s2_op_ticket, ycommon name(p1, replace) col(1)
graph combine p1 vig2s2_op_demeanor, ycommon name(S2_vig2_oprobitmfx, replace) title("Study 2, Ordered Probit Marginal Effects")

**************************************************************************************************
* Study 2, Figure Figure 2
* Treatments affect threat
**************************************************************************************************

foreach var of varlist s2_out_threat_vic s2_out_threat_cop  {

	tab `var'
	tab `var', nol

	regress `var' i.S2treat_demeanor i.treat_weapon i.treat_officerwhite, robust
	est store `var'
	
	qui summ `var' if e(sample)
	local sampmean=r(mean)
	
	* Predicted outcome for baseline category
	local base_`var' = _b[_cons]
	
	outreg using TableA5_Study2Results.out, se bracket rdec(2) bdec(2) adec(2) 3aster addstat("Sample mean",`sampmean') append
	
	* Model with demographics
	regress `var' i.S2treat_demeanor i.treat_weapon i.treat_officerwhite D_*, robust
	outreg using TableA6_Study2ResultsWithCovariates.out, se bracket rdec(2) bdec(2) 3aster append
}

* Create Figure 2, Panel A
local baseline : display %4.2f `base_s2_out_threat_vic'

coefplot s2_out_threat_vic , drop(_cons) levels(95) omitted baselevels headings(0.treat_officerwhite = `"{bf:Officer Race}"' 1.S2treat_demeanor = "{bf:Demeanor}"0.treat_weapon= "{bf:Weapon}") xline(0) title("A) Threat to Victim", span size(small)) xlabel(, labels labsize(vsmall)) xtitle("Perceived Threat") ylabel(, labels labsize(small)) legend(off) note("Threat to victim ranges from 1 to 5." "Predicted baseline threat for Black officer/Both polite/No weapon is `baseline'", span size(vsmall))  xscale(range(-.25(.5).75)) xlabel(-.25(.25).75) grid(within ) name(F2A_threatvic, replace) 

* Create Figure 2, Panel B
local baseline : display %4.2f `base_s2_out_threat_cop'

coefplot s2_out_threat_cop , drop(_cons) levels(95) omitted baselevels headings(0.treat_officerwhite = `"{bf:Officer Race}"' 1.S2treat_demeanor = "{bf:Demeanor}"0.treat_weapon= "{bf:Weapon}") xline(0) title("B) Threat to Officer", span size(small)) xlabel(, labels labsize(vsmall)) xtitle("Perceived Threat") ylabel(, labels labsize(small)) legend(off) note("Threat to officer ranges from 1 to 5." "Predicted baseline threat for Black officer/Both polite/No weapon is `baseline'", span size(vsmall))  xscale(range(-.25(.5).75)) xlabel(-.25(.25).75) grid(within) name(F2B_threatcop, replace) 

* Create combined Figure 2, panels A and B
graph combine F2A_threatvic F2B_threatcop, xcommon cols(1) title(Experiment #2: Effect of Vignette Characteristics on Perceived Threat, size(small)) note("Point estimates displayed with 95% confidence intervals. Prior to punishment being revealed. Regression results appear in Appendix Table A2.", size(vsmall))  name(Figure2_Combined, replace) xsize(9) ysize(6.5) scale(.9)
graph export Figure2.pdf, replace

* HERE IS THE TEST FOR RACE OF OFFICER INTERACTIONS. NULLS. REPORTED IN TEXT
foreach var of varlist s2_out_threat_vic s2_out_threat_cop  {
	qui regress `var' i.treat_officerwhite i.S2treat_demeanor i.treat_weapon
	estimates store base

	qui regress `var' i.treat_officerwhite##ib1.S2treat_demeanor i.treat_officerwhite##i.treat_weapon
	estimates store m_racedemortic

	di "DV=`var' Test of whether race x demeanor and race x weapon interactions improve fit"
	lrtest base m_racedemortic , stats
}

* HERE IS THE TEST FOR DEMEANOR X WEAPON. FOr threat to victim, significant. REPORTED IN TEXT AS APPENDIX FIGURE 2
foreach var of varlist s2_out_threat_vic s2_out_threat_cop  {

	qui regress `var' i.treat_officerwhite i.S2treat_demeanor i.treat_weapon
	estimates store base
	
	regress `var' i.treat_officerwhite i.S2treat_demeanor##i.treat_weapon
	estimates store m_demeanorweapon

	di "DV=`var' Test of whether demeanor x weapons interactions improve fit"
	lrtest base m_demeanorweapon , stats
}

* Threat analysis with demeanor x weapon interactions
foreach var of varlist s2_out_threat_vic s2_out_threat_cop  {
	regress `var' i.treat_officerwhite i.S2treat_demeanor##i.treat_weapon, robust
	est store `var'
}

* Create Panel A of unused figured
local baseline : display %4.2f `base_s2_out_threat_vic'

coefplot s2_out_threat_vic , drop(_cons) levels(95) omitted headings(1.treat_officerwhite = `"{bf:Officer Race}"' 2.S2treat_demeanor = "{bf:Demeanor}" 1.treat_weapon= "{bf:Weapon}" 2.S2treat_demeanor##1.treat_weapon= "{bf:Weapon x Demeanor}") xline(0) title("A) Threat to Victim", span size(small)) xlabel(, labels labsize(vsmall)) xtitle("Perceived Threat") ylabel(, labels labsize(small)) legend(off) note("Threat to victim ranges from 1 to 5.", span size(vsmall))  xscale(range(-.25(.5).75)) xlabel(-.25(.25).75) grid(within ) name(weapondemeanor_threatvic, replace) 

* Create Panel B of unused figured
local baseline : display %4.2f `base_s2_out_threat_cop'

coefplot s2_out_threat_cop , drop(_cons) levels(95) omitted  headings(1.treat_officerwhite = `"{bf:Officer Race}"' 2.S2treat_demeanor = "{bf:Demeanor}" 1.treat_weapon= "{bf:Weapon}" 2.S2treat_demeanor##1.treat_weapon= "{bf:Weapon x Demeanor}") xline(0) title("A) Threat to Officer", span size(small)) xlabel(, labels labsize(vsmall)) xtitle("Perceived Threat") ylabel(, labels labsize(small)) legend(off) note("Threat to officer ranges from 1 to 5.", span size(vsmall))  xscale(range(-.25(.5).75)) xlabel(-.25(.25).75) grid(within ) name(weapondemeanor_threatcop, replace) 

* Create combined Figure, panels A and B
graph combine weapondemeanor_threatvic weapondemeanor_threatcop, xcommon cols(1) title(Experiment #2: Effect of Vignette Characteristics on Perceived Threat) note(Point estimates displayed with 95% confidence intervals. This is prior to punishment being revealed.) name(Threat_Combined, replace) xsize(9) ysize(6.5) scale(.9)

**************************************************************************************************
* Experiment 1, Figures 3 and 4
* Specifications without interactions, after punishment is revealed
* Fairness of punishment, and global fairness
**************************************************************************************************

* Specifications without interactions, after punishment is revealed.
foreach var of varlist S1out_fair_pun_vig2 S1out_fair_global_vig2 {
	regress `var' i.S1treat_demeanor  i.treat_officerwhite i.treat_ticket, robust
	qui summ `var' if e(sample)
	local sampmean=r(mean)

	* Predicted outcome for baseline category
	local base_`var' = _b[_cons]

	* Effect of civilian becoming hostile given officer already hostile
	* So does civilian stay calm? How much worse is for the civilian to get angry back?
	lincom 4.S1treat_demeanor - 5.S1treat_demeanor
	local est45=r(estimate)
	local p_est45=r(p)

	* Effect of civilian rather than officer starting hostile interaction
	lincom 3.S1treat_demeanor - 4.S1treat_demeanor
	local est34=r(estimate)
	local p_est34=r(p)	

	est store `var'
	
	outreg using TableA1_Study1Results.out, se bracket rdec(2) bdec(2) 3aster addstat("Sample mean",`sampmean',"FX Civ. responds to hostility vs remains polite",`est45',"p. diff 1",`p_est45',"FX Civ. rather than officer starting hostile interaction",`est34',"p. diff 2",`p_est34') adec(2) append
	
	* Manual interaction coefficients to work with outreg
	regress `var' i.treat_officerwhite i.S1treat_demeanor i.treat_ticket S1_X_demeanor*_ticket, robust
	outreg using TableA1_Study1Results.out, se bracket rdec(2) bdec(2) 3aster ctitle("(Demeanor-Punishment Interactions)") append
	
	regress `var' i.S1treat_demeanor  i.treat_officerwhite i.treat_ticket D_*, robust
	outreg using TableA2_Study1ResultsWithCovariates.out, se bracket rdec(2) bdec(2) 3aster append
}

* Create Figure 3, Panel A
local baseline : display %4.2f `base_S1out_fair_pun_vig2'
coefplot S1out_fair_pun_vig2 , drop(_cons) levels(95) omitted baselevels headings(0.treat_officerwhite = `"{bf:Officer Race}"' 1.S1treat_demeanor = "{bf:Demeanor}" 0.treat_ticket = "{bf:Punishment}") xline(0) title("A) Experiment #1", span size(small)) xlabel(, labels labsize(vsmall)) xtitle("Perceived Fairness of Punishment") ylabel(, labels labsize(small)) legend(off) note("Perceived fairness ranges from 1 to 5." "Predicted perceived fairness for Black officer/Both polite/Escorted from park is `baseline'", span size(vsmall)) xscale(range(-.75(.25).75)) xlabel(-.5(.25).5) grid(within )  name(F3A_S1_out_fair_pun_vig2, replace)  

* Create Figure 4, Panel A
local baseline : display %4.2f `base_S1out_fair_global_vig2'
coefplot S1out_fair_global_vig2 , drop(_cons) levels(95) omitted baselevels headings(0.treat_officerwhite = `"{bf:Officer Race}"' 1.S1treat_demeanor = "{bf:Demeanor}" 0.treat_ticket = "{bf:Punishment}") xline(0) title("A) Experiment #1", span size(small)) xlabel(, labels labsize(vsmall)) xtitle("Perceived Fairness of Interaction") ylabel(, labels labsize(small)) legend(off) note("Overall fairness ranges from 1 to 5." "Predicted perceived fairness for Black officer/Both polite/Escorted from park is `baseline'", span size(vsmall)) xscale(range(-1.5(.25).5)) xlabel(-1.5(.5).5) grid(within )  name(F4A_S1_out_fairness_global_vig2, replace) 

**************************************************************************************************
* Experiment R1, Figures 3 and 4
* Specifications without interactions, after punishment is revealed
* Fairness of punishment, and global fairness
**************************************************************************************************

foreach var of varlist SR1_out_fairpun SR1_out_fairciv {
	regress `var' i.T_demeanor i.T_officerwhite i.T_civilianwhite i.T_officerdecision, robust
	qui summ `var' if e(sample)
	local sampmean=r(mean)

	est store `var'

	* Predicted outcome for baseline category
	local base_`var' = _b[_cons]
	outreg using TableA3_StudyR1Results.out, se bracket rdec(2) bdec(2) adec(2) 3aster addstat("Sample mean",`sampmean') append

	* with Demographics
	regress `var' i.T_demeanor i.T_officerwhite i.T_civilianwhite i.T_officerdecision d_*, robust
	outreg using TableA4_StudyR1ResultsWithCovariates.out, se bracket rdec(2) bdec(2) 3aster append
	
	* Black respondents
	regress `var' i.T_demeanor i.T_officerwhite i.T_civilianwhite i.T_officerdecision if d_black==1, robust
	est store `var'_blk

	qui summ `var' if e(sample)
	outreg using TableA4_StudyR1ResultsWithCovariates.out, se bracket rdec(2) bdec(2) adec(2) 3aster ctitle("Black respondents") addstat("Sample mean",`r(mean)') append
	
	* White respondents
	regress `var' i.T_demeanor i.T_officerwhite i.T_civilianwhite i.T_officerdecision if d_black==0 & d_asian==0 & d_other==0, robust
	est store `var'_wht

	qui summ `var' if e(sample)
	outreg using TableA4_StudyR1ResultsWithCovariates.out, se bracket rdec(2) bdec(2) adec(2) 3aster ctitle("White respondents (Incl. Hispanic)") addstat("Sample mean",`r(mean)') append
	
	* Robustness of office/civilian race interactions: Effect only manifests when both are white.
	regress `var' i.T_demeanor T_x_bothwhite T_x_offwhitecivblack T_x_offwblackcivwhite i.T_officerdecision, robust
	outreg using TableA3_StudyR1Results.out, se bracket rdec(2) bdec(2) 3aster append
	
	* Manual interaction coefficients to work with outreg
	regress `var' i.T_demeanor i.T_officerdecision SR1_X_demeanor*_ticket i.T_officerwhite i.T_civilianwhite, robust
	outreg using TableA3_StudyR1Results.out, se bracket rdec(2) bdec(2) 3aster ctitle("(Demeanor-Punishment Interactions)") append
	
}

* Create Figure 3, Panel B
local baseline : display %4.2f `base_SR1_out_fairpun'

coefplot SR1_out_fairpun , drop(_cons) levels(95) omitted baselevels headings(0.T_civilianwhite = `"{bf:Civilian Race}"' 0.T_officerwhite = `"{bf:Officer Race}"' 0.T_demeanor = "{bf:Demeanor}" 0.T_officerdecision = "{bf:Punishment}") xline(0) title("B) Experiment R1", span size(small)) xlabel(, labels labsize(vsmall)) xtitle("Perceived Fairness of Punishment") ylabel(, labels labsize(small)) legend(off) note("Perceived fairness ranges from 1 to 5." "Predicted perceived fairness for White officer/White civilian/Both polite/Escorted from park is `baseline'", span size(vsmall)) xscale(range(-.25(.25)1)) xlabel(-.25(.25)1) grid(within ) name(F3B_SR1_out_fairpun, replace)

* Create Figure 4, Panel B
local baseline : display %4.2f `base_SR1_out_fairciv'

coefplot SR1_out_fairciv , drop(_cons) levels(95) omitted baselevels headings(0.T_civilianwhite = `"{bf:Civilian Race}"' 0.T_officerwhite = `"{bf:Officer Race}"' 0.T_demeanor = "{bf:Demeanor}" 0.T_officerdecision = "{bf:Punishment}") xline(0) title("B) Experiment R1", span size(small)) xlabel(, labels labsize(vsmall)) xtitle("Perceived Fairness of Punishment") ylabel(, labels labsize(small)) legend(off) note("Perceived fairness ranges from 1 to 5." "Predicted perceived fairness for White officer/White civilian/Both polite/Escorted from park is `baseline'", span size(vsmall)) xscale(range(-1.5(.25).5)) xlabel(-1.5(.5).5) grid(within ) name(F4B_SR1_out_fairciv, replace)

**************************************************************************************************
* Experiment 2, Figures 3 4
* Specifications without interactions, after punishment is revealed
* Preferred punishment, fairness of punishment, and global fairness
**************************************************************************************************

foreach var of varlist s2_out_fairnesspun s2_out_fairnesglob {
	regress `var' i.S2treat_demeanor i.treat_weapon i.treat_officerwhite i.treat_arrest, robust
	est store `var'

	qui summ `var' if e(sample)
	local sampmean=r(mean)

	* Predicted outcome for baseline category
	local base_`var' = _b[_cons]
	
	outreg using TableA5_Study2Results.out, se bracket rdec(2) bdec(2) adec(2) 3aster addstat("Sample mean",`sampmean') append
	
	* Manual interaction coefficients to work with outreg
	regress `var' i.treat_officerwhite i.S2treat_demeanor i.treat_arrest i.treat_weapon i.treat_arrest i.treat_arrest S2_X_*, robust
	outreg using TableA5_Study2Results.out, se bracket rdec(2) bdec(2) 3aster ctitle("(Demeanor-Punishment Interactions)") append
		
	* Model with demographics
	regress `var' i.S2treat_demeanor i.treat_weapon i.treat_officerwhite i.treat_arrest D_*, robust
	outreg using TableA6_Study2ResultsWithCovariates.out, se bracket rdec(2) bdec(2) 3aster append
	
}

* Create Figure 3, Panel C
local baseline : display %4.2f `base_s2_out_fairnesspun'
coefplot s2_out_fairnesspun , drop(_cons) levels(95) omitted baselevels headings(0.treat_officerwhite = `"{bf:Officer Race}"' 1.S2treat_demeanor = "{bf:Demeanor}"0.treat_weapon= "{bf:Weapon}" 0.treat_arrest = "{bf:Punishment}") xline(0) title("C) Experiment #2", span size(small)) xlabel(, labels labsize(vsmall)) xtitle("Perceived Fairness of Punishment") ylabel(, labels labsize(small)) legend(off) note("Perceived fairness ranges from 1 to 5." "Predicted perceived fairness for Black officer/Both polite/No weapon/Ticketed is `baseline'", span size(vsmall)) xscale(range(-.75(.25).75)) xlabel(-.5(.25).5) grid(within )  name(F3C_S2_out_fair_pun_vig2, replace)  

* Create Figure 4, Panel C
local baseline : display %4.2f `base_s2_out_fairnesglob'
coefplot s2_out_fairnesglob , drop(_cons) levels(95) omitted baselevels headings(0.treat_officerwhite = `"{bf:Officer Race}"' 1.S2treat_demeanor = "{bf:Demeanor}"0.treat_weapon= "{bf:Weapon}" 0.treat_arrest = "{bf:Punishment}") xline(0) title("C) Experiment #2", span size(small)) xlabel(, labels labsize(vsmall)) xtitle("Perceived Fairness of Interaction") ylabel(, labels labsize(small)) legend(off) note("Overall fairness ranges from 1 to 5." "Predicted perceived fairness for Black officer/Both polite/No weapon/Ticketed is `baseline'", span size(vsmall)) xscale(range(-1.5(.25).5)) xlabel(-1.5(.5).5) grid(within )  name(F4C_S2_out_fairness_global_vig2, replace) 

graph combine F3A_S1_out_fair_pun_vig2 F3B_SR1_out_fairpun F3C_S2_out_fair_pun_vig2,  cols(1) title("Effect of Vignette Characteristics on Perceived Fairness of Punishment", size(medium)) note("Point estimates displayed with 95% confidence intervals. Complete regression results appear in Tables A1, A2, and A3.", size(vsmall))  name(Figure3_Combined, replace) xsize(6.5) ysize(9) scale(.8)
graph export Figure3.pdf, replace

graph combine F4A_S1_out_fairness_global_vig2 F4B_SR1_out_fairciv F4C_S2_out_fairness_global_vig2,  cols(1) title("Effect of Vignette Characteristics on Perceived Fairness of Interaction", size(medium)) note("Point estimates displayed with 95% confidence intervals. Complete regression results appear in Tables A1, A2, and A3.", size(vsmall)) name(Figure4_Combined, replace) xsize(6.5) ysize(9) scale(.8)
graph export Figure4.pdf, replace

**************************************************************************************************
* Fairness of assigned punishment
* Block F-tests of effect of including interactions of race with punishment on fairness of punishment
* All are null and are reported in footnote in main text
**************************************************************************************************

* Test for race interactions. All null
* Study 1:
regress S1out_fair_pun_vig2 i.treat_officerwhite i.S1treat_demeanor i.treat_ticket
est store base
regress S1out_fair_pun_vig2 i.treat_officerwhite##i.S1treat_demeanor i.treat_officerwhite##i.treat_ticket
est store race
lrtest base race, stats

* Study R1:
regress SR1_out_fairpun i.T_demeanor i.T_officerwhite i.T_civilianwhite i.T_officerdecision
est store base
regress SR1_out_fairpun i.T_demeanor##i.T_officerwhite i.T_civilianwhite i.T_officerdecision
est store race
lrtest base race, stats

* Study 2:
regress s2_out_fairnesspun i.treat_officerwhite i.S2treat_demeanor i.treat_weapon i.treat_arrest
est store base
regress s2_out_fairnesspun i.treat_officerwhite##i.S2treat_demeanor i.treat_officerwhite##i.treat_weapon i.treat_officerwhite##i.treat_arrest
est store race
lrtest base race, stats

**************************************************************************************************
* Fairness of assigned punishment
* Block F-tests of effect of including interactions of demeanor/weapon with punishment on fairness of punishment
* All are significant. MFX Reported in Table 4.
**************************************************************************************************


* Test for demeanor (and weapon, study 2) ticket interactions (Note: can't do robust here, as LR test doesn't work)
* Study 1:
regress S1out_fair_pun_vig2 i.treat_officerwhite i.S1treat_demeanor i.treat_ticket
est store base
regress S1out_fair_pun_vig2 i.treat_officerwhite i.S1treat_demeanor##i.treat_ticket
est store dem
lrtest base dem , stats

* Complete interaction model for below MFX code
regress S1out_fair_pun_vig2 i.treat_officerwhite i.S1treat_demeanor##i.treat_ticket, robust

*Local variable used to store MFX estimates.
gen mfxlabel =""
label var mfxlabel "Study"
replace mfxlabel = "Experiment 1" in 1
replace mfxlabel = "Experiment R1" in 3
replace mfxlabel  = "Experiment 2" in 5
gen mfx1=""
gen mfx2=""
gen mfx3=""
label var mfx1 "Baseline (SE)"
label var mfx2 "Civilian Hostile, Officer Polite (SE)"
label var mfx3 "Civilian Armed (SE)"

lincom 1.treat_ticket
local betatxt : display %4.2f `r(estimate)'
local sen : display %4.2f `r(se)'
local setxt = "'(" + "`sen'" + ")"
if `r(p)' <.10 {
	local setxt = "`setxt'" + "*"
	}
if `r(p)' <.05 {
	local setxt = "`setxt'" + "*"
	}
if `r(p)' <.01 {
	local setxt = "`setxt'" + "*"
	}
di "`setxt'"

replace mfx1="`betatxt'" in 1
replace mfx1="`setxt'" in 2

lincom 1.treat_ticket+2.S1treat_demeanor+2.S1treat_demeanor#1.treat_ticket

local betatxt : display %4.2f `r(estimate)'
local sen : display %4.2f `r(se)'
local setxt = "'(" + "`sen'" + ")"
if `r(p)' <.10 {
	local setxt = "`setxt'" + "*"
	}
if `r(p)' <.05 {
	local setxt = "`setxt'" + "*"
	}
if `r(p)' <.01 {
	local setxt = "`setxt'" + "*"
	}
di "`setxt'"

replace mfx2="`betatxt'" in 1
replace mfx2="`setxt'" in 2

lincom 2.S1treat_demeanor+2.S1treat_demeanor#1.treat_ticket

* Study R1:

regress SR1_out_fairpun i.T_demeanor i.T_officerwhite i.T_civilianwhite i.T_officerdecision
est store base
regress SR1_out_fairpun i.T_demeanor##i.T_officerdecision i.T_officerwhite i.T_civilianwhite 
est store dem
lrtest base dem , stats

* Complete interaction model for below MFX code
regress SR1_out_fairpun i.T_demeanor##i.T_officerdecision i.T_officerwhite i.T_civilianwhite, robust

lincom 1.T_officerdecision

local betatxt : display %4.2f `r(estimate)'
local sen : display %4.2f `r(se)'
local setxt = "'(" + "`sen'" + ")"
if `r(p)' <.10 {
	local setxt = "`setxt'" + "*"
	}
if `r(p)' <.05 {
	local setxt = "`setxt'" + "*"
	}
if `r(p)' <.01 {
	local setxt = "`setxt'" + "*"
	}
di "`setxt'"

replace mfx1="`betatxt'" in 3
replace mfx1="`setxt'" in 4

lincom 1.T_officerdecision+1.T_demeanor+1.T_demeanor#1.T_officerdecision

local betatxt : display %4.2f `r(estimate)'
local sen : display %4.2f `r(se)'
local setxt = "'(" + "`sen'" + ")"
if `r(p)' <.10 {
	local setxt = "`setxt'" + "*"
	}
if `r(p)' <.05 {
	local setxt = "`setxt'" + "*"
	}
if `r(p)' <.01 {
	local setxt = "`setxt'" + "*"
	}
di "`setxt'"

replace mfx2="`betatxt'" in 3
replace mfx2="`setxt'" in 4

lincom 1.T_demeanor+1.T_demeanor#1.T_officerdecision

* Study 2:

regress s2_out_fairnesspun i.treat_officerwhite i.S2treat_demeanor i.treat_weapon i.treat_arrest
est store base
regress s2_out_fairnesspun i.treat_officerwhite i.S2treat_demeanor##i.treat_arrest i.treat_weapon##i.treat_arrest i.treat_arrest
est store dem
lrtest base dem , stats

* Complete interaction model for below MFX code
regress s2_out_fairnesspun i.treat_officerwhite i.S2treat_demeanor##i.treat_arrest i.treat_weapon##i.treat_arrest i.treat_arrest, robust

lincom 1.treat_arrest

local betatxt : display %4.2f `r(estimate)'
local sen : display %4.2f `r(se)'
local setxt = "'(" + "`sen'" + ")"
if `r(p)' <.10 {
	local setxt = "`setxt'" + "*"
	}
if `r(p)' <.05 {
	local setxt = "`setxt'" + "*"
	}
if `r(p)' <.01 {
	local setxt = "`setxt'" + "*"
	}
di "`setxt'"

replace mfx1="`betatxt'" in 5
replace mfx1="`setxt'" in 6

lincom 1.treat_arrest+2.S2treat_demeanor+2.S2treat_demeanor#1.treat_arrest

local betatxt : display %4.2f `r(estimate)'
local sen : display %4.2f `r(se)'
local setxt = "'(" + "`sen'" + ")"
if `r(p)' <.10 {
	local setxt = "`setxt'" + "*"
	}
if `r(p)' <.05 {
	local setxt = "`setxt'" + "*"
	}
if `r(p)' <.01 {
	local setxt = "`setxt'" + "*"
	}
di "`setxt'"

replace mfx2="`betatxt'" in 5
replace mfx2="`setxt'" in 6

lincom 2.S2treat_demeanor+2.S2treat_demeanor#1.treat_arrest

lincom 1.treat_arrest+1.treat_weapon+1.treat_weapon#1.treat_arrest

local betatxt : display %4.2f `r(estimate)'
local sen : display %4.2f `r(se)'
local setxt = "'(" + "`sen'" + ")"
if `r(p)' <.10 {
	local setxt = "`setxt'" + "*"
	}
if `r(p)' <.05 {
	local setxt = "`setxt'" + "*"
	}
if `r(p)' <.01 {
	local setxt = "`setxt'" + "*"
	}
di "`setxt'"

replace mfx3="`betatxt'" in 5
replace mfx3="`setxt'" in 6

lincom 1.treat_weapon+1.treat_weapon#1.treat_arrest

* Outsheet Table 4.
preserve

	order mfxlabel
	keep mfx*
	keep in 1/6

	outsheet using Table4.csv, names replace comma

restore

**************************************************************************************************
* Global fairness
* Block F-tests of effect of including interactions of race with punishment on global fairness
* All are null and are reported in footnote in main text
**************************************************************************************************

* Test for race interactions. All null
* Study 1:
regress S1out_fair_global_vig2 i.treat_officerwhite i.S1treat_demeanor i.treat_ticket
est store base
regress S1out_fair_global_vig2 i.treat_officerwhite##i.S1treat_demeanor i.treat_officerwhite##i.treat_ticket
est store race
lrtest base race, stats

* Study R1:
regress SR1_out_fairciv i.T_demeanor i.T_officerwhite i.T_civilianwhite i.T_officerdecision
est store base
regress SR1_out_fairciv i.T_demeanor##i.T_officerwhite i.T_civilianwhite i.T_officerdecision
est store race
lrtest base race, stats

* Study 2:
regress s2_out_fairnesglob i.treat_officerwhite i.S2treat_demeanor i.treat_weapon i.treat_arrest
est store base
regress s2_out_fairnesglob i.treat_officerwhite##i.S2treat_demeanor i.treat_officerwhite##i.treat_weapon i.treat_officerwhite##i.treat_arrest
est store race
lrtest base race, stats

**************************************************************************************************
* Global fairness
* Block F-tests of effect of including interactions of demeanor/weapon with punishment on global fairness
* All are significant. MFX Reported in Table 5.
**************************************************************************************************

* Test for demeanor (and weapon, study 2) ticket interactions
* Study 1:
regress S1out_fair_global_vig2 i.treat_officerwhite i.S1treat_demeanor i.treat_ticket
est store base
regress S1out_fair_global_vig2 i.treat_officerwhite i.S1treat_demeanor##i.treat_ticket
est store dem
lrtest base dem , stats

* for mfx code
regress S1out_fair_global_vig2 i.treat_officerwhite i.S1treat_demeanor##i.treat_ticket, robust

*Reuse local variable from above to store MFX estimates.
lincom 1.treat_ticket
local betatxt : display %4.2f `r(estimate)'
local sen : display %4.2f `r(se)'
local setxt = "'(" + "`sen'" + ")"
if `r(p)' <.10 {
	local setxt = "`setxt'" + "*"
	}
if `r(p)' <.05 {
	local setxt = "`setxt'" + "*"
	}
if `r(p)' <.01 {
	local setxt = "`setxt'" + "*"
	}
di "`setxt'"

replace mfx1="`betatxt'" in 1
replace mfx1="`setxt'" in 2

lincom 1.treat_ticket+2.S1treat_demeanor+2.S1treat_demeanor#1.treat_ticket

local betatxt : display %4.2f `r(estimate)'
local sen : display %4.2f `r(se)'
local setxt = "'(" + "`sen'" + ")"
if `r(p)' <.10 {
	local setxt = "`setxt'" + "*"
	}
if `r(p)' <.05 {
	local setxt = "`setxt'" + "*"
	}
if `r(p)' <.01 {
	local setxt = "`setxt'" + "*"
	}
di "`setxt'"

replace mfx2="`betatxt'" in 1
replace mfx2="`setxt'" in 2

lincom 2.S1treat_demeanor+2.S1treat_demeanor#1.treat_ticket

* Study R1:
regress SR1_out_fairciv i.T_demeanor i.T_officerwhite i.T_civilianwhite i.T_officerdecision
est store base
regress SR1_out_fairciv i.T_demeanor##i.T_officerdecision i.T_officerwhite i.T_civilianwhite 
est store dem
lrtest base dem , stats

* for mfx code
regress SR1_out_fairciv i.T_demeanor##i.T_officerdecision i.T_officerwhite i.T_civilianwhite, robust

lincom 1.T_officerdecision

local betatxt : display %4.2f `r(estimate)'
local sen : display %4.2f `r(se)'
local setxt = "'(" + "`sen'" + ")"
if `r(p)' <.10 {
	local setxt = "`setxt'" + "*"
	}
if `r(p)' <.05 {
	local setxt = "`setxt'" + "*"
	}
if `r(p)' <.01 {
	local setxt = "`setxt'" + "*"
	}
di "`setxt'"

replace mfx1="`betatxt'" in 3
replace mfx1="`setxt'" in 4

lincom 1.T_officerdecision+1.T_demeanor+1.T_demeanor#1.T_officerdecision

local betatxt : display %4.2f `r(estimate)'
local sen : display %4.2f `r(se)'
local setxt = "'(" + "`sen'" + ")"
if `r(p)' <.10 {
	local setxt = "`setxt'" + "*"
	}
if `r(p)' <.05 {
	local setxt = "`setxt'" + "*"
	}
if `r(p)' <.01 {
	local setxt = "`setxt'" + "*"
	}
di "`setxt'"

replace mfx2="`betatxt'" in 3
replace mfx2="`setxt'" in 4

lincom 1.T_demeanor+1.T_demeanor#1.T_officerdecision

* Study 2:
regress s2_out_fairnesglob i.treat_officerwhite i.S2treat_demeanor i.treat_weapon i.treat_arrest
est store base
regress s2_out_fairnesglob i.treat_officerwhite i.S2treat_demeanor##i.treat_arrest i.treat_weapon##i.treat_arrest i.treat_arrest
est store dem
lrtest base dem , stats

* for mfx Code
regress s2_out_fairnesglob i.treat_officerwhite i.S2treat_demeanor##i.treat_arrest i.treat_weapon##i.treat_arrest i.treat_arrest, robust

lincom 1.treat_arrest

local betatxt : display %4.2f `r(estimate)'
local sen : display %4.2f `r(se)'
local setxt = "'(" + "`sen'" + ")"
if `r(p)' <.10 {
	local setxt = "`setxt'" + "*"
	}
if `r(p)' <.05 {
	local setxt = "`setxt'" + "*"
	}
if `r(p)' <.01 {
	local setxt = "`setxt'" + "*"
	}
di "`setxt'"

replace mfx1="`betatxt'" in 5
replace mfx1="`setxt'" in 6

lincom 1.treat_arrest+2.S2treat_demeanor+2.S2treat_demeanor#1.treat_arrest

local betatxt : display %4.2f `r(estimate)'
local sen : display %4.2f `r(se)'
local setxt = "'(" + "`sen'" + ")"
if `r(p)' <.10 {
	local setxt = "`setxt'" + "*"
	}
if `r(p)' <.05 {
	local setxt = "`setxt'" + "*"
	}
if `r(p)' <.01 {
	local setxt = "`setxt'" + "*"
	}
di "`setxt'"

replace mfx2="`betatxt'" in 5
replace mfx2="`setxt'" in 6

lincom 2.S2treat_demeanor+2.S2treat_demeanor#1.treat_arrest

lincom 1.treat_arrest+1.treat_weapon+1.treat_weapon#1.treat_arrest

local betatxt : display %4.2f `r(estimate)'
local sen : display %4.2f `r(se)'
local setxt = "'(" + "`sen'" + ")"
if `r(p)' <.10 {
	local setxt = "`setxt'" + "*"
	}
if `r(p)' <.05 {
	local setxt = "`setxt'" + "*"
	}
if `r(p)' <.01 {
	local setxt = "`setxt'" + "*"
	}
di "`setxt'"

replace mfx3="`betatxt'" in 5
replace mfx3="`setxt'" in 6

lincom 1.treat_weapon+1.treat_weapon#1.treat_arrest

* Outsheet Table 5.
preserve

	order mfxlabel
	keep mfx*
	keep in 1/6

	outsheet using Table5.csv, names replace comma

restore
